/*
 * SCOR.h
 *
 * Author: Samuel Queiroz
 */

#ifndef SCOR_H_
#define SCOR_H_

#define POSITIVE_OFFSET 5
#define NEGATIVE_OFFSET -5
#define MAXIMUM_SPEED 35
#define SPEED_UNITS 20
#define ROTATION_UNITS 10

#include "GUI/GUI.h"

#include "Robot/Robot.h"

#include "Control/Keyboard.h"
#include "Control/Joystick.h"
#include "Control/SDLWrapper.h"

#include "Component/Button.h"
#include "Component/Slider.h"
#include "Component/Switcher.h"

#include "SDL/SDL.h"

class SCOR
{

private:

	GUI *gui;

	Robot leftRobot;
	Robot rightRobot;

	Keyboard *keyboard;
	Joystick *joystick;
	SDLWrapper *sdlWrapper;

	void treatAndMove();

	void treatKeyboardAndMove();

	void treatJoystickAndMove();

	void calculateSpeed(
			int x,
			int y,
			int * leftSpeed,
			int * rightSpeed);

public:

	SCOR()
	{
		this->sdlWrapper = new SDLWrapper();
		this->keyboard = new Keyboard(
				SPEED_UNITS,
				ROTATION_UNITS,
				sdlWrapper->getEvent());
		this->joystick = new Joystick(
				SPEED_UNITS,
				ROTATION_UNITS,
				sdlWrapper->getEvent(),
				sdlWrapper->getLeftXAxis(),
				sdlWrapper->getLeftYAxis(),
				sdlWrapper->getRightXAxis(),
				sdlWrapper->getRightYAxis());

		this->sdlWrapper->addListenerObject(keyboard);
		this->sdlWrapper->addListenerObject(joystick);

		this->gui = new GUI(
				keyboard->getUpButton(),
				keyboard->getDownButton(),
				keyboard->getLeftButton(),
				keyboard->getRightButton(),
				joystick->getLeftButton(),
				joystick->getRightButton(),
				keyboard->getRobotSwitcher(),
				keyboard->getControlSwitcher(),
				keyboard->getSpeedSlider(),
				keyboard->getRotationSlider());

		leftRobot.connect("/dev/ttyUSB0");
		rightRobot.connect("/dev/ttyUSB1");
	}

	~SCOR()
	{

	}

	void run();

};

#endif
